<template>
  <div>
    <a-input @change="onChange" v-model="args" :placeholder="i18n('predicate.comma','逗号分割')"></a-input>
  </div>
</template>

<script>
  export default {
    name: "HostEdit",
    props: ["value"],
    data() {
      return {
        args: ""
      }
    },
    created() {
      this.init();
    },
    methods: {
      i18n(name,text,key){
        return this.$ti18(name,text,"SysRouting",key);
      },
      init() {
        if (this.value.predicateArgs) {
          var predicateArgs = JSON.parse(this.value.predicateArgs);
          var predicateArgsStr = "";
          var ary = [];//用于转换数组
          for (var index in predicateArgs) {
            ary.push({[index]: (predicateArgs)[index]})
          }
          for (var i = 0; i < ary.length; i++) {
            if (i > 0) {
              predicateArgsStr += ",";
            }
            predicateArgsStr += (ary[i]["_genkey_" + i]);
          }
          this.args = predicateArgsStr;
        }
      },
      onChange() {
        var argsAry = (this.args).split(",");
        var obj={};
        for (var i = 0; i < argsAry.length; i++) {
            obj["_genkey_"+i]=argsAry[i];
        }
        this.value.predicateArgs=JSON.stringify(obj);
      }

    },
  }
</script>

<style scoped>

</style>